package com.jy.adscm.operation.aftersales.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.aftersales.bean.ShylMaterialdetail;
import com.jy.adscm.operation.aftersales.mapper.mysql.ShylMaterialdetailMapper;
import com.jy.adscm.operation.aftersales.service.ShylMaterialdetailService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.operation.cg.bean.CgMaterial;
import com.jy.adscm.operation.cg.mapper.mysql.CgMaterialMapper;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 原料出库记录 服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-08-12
 */
@Service
public class ShylMaterialdetailServiceImpl extends ServiceImpl<ShylMaterialdetailMapper, ShylMaterialdetail> implements ShylMaterialdetailService {
    @Autowired
    JyUserMapper jyUserMapper;
    @Autowired
    CgMaterialMapper cgMaterialMapper;
    @Override
    public boolean insertShylMaterialdetail(ShylMaterialdetail shylMaterialdetail, Token token) {
        return false;
    }

    @Override
    public List<ShylMaterialdetail> selectByTid(String tid) {
        Wrapper<ShylMaterialdetail> wrapper=new EntityWrapper<>();
        wrapper.eq("tid",tid);
        List<ShylMaterialdetail> shylMaterialdetails = super.selectList(wrapper);
        for (ShylMaterialdetail shylMaterialdetail : shylMaterialdetails) {
            if (AdscmBaseUtils.getInstance().isNotEmpty(shylMaterialdetail.getUseperson(),null)){
                JyUser jyUser = jyUserMapper.selectById(shylMaterialdetail.getUseperson());
                shylMaterialdetail.setUsepersonName(jyUser.getName());
            }
            if (AdscmBaseUtils.getInstance().isNotEmpty(shylMaterialdetail.getName(),null)){
                CgMaterial cgMaterial = cgMaterialMapper.selectById(shylMaterialdetail.getName());
                shylMaterialdetail.setNameName(cgMaterial.getName());
            }
        }
        return shylMaterialdetails;
    }
}
